package org.example.cloudalibaba.myhandler;

import cn.hutool.core.util.IdUtil;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.example.springcloud.common.Result;

public class MyBlockHandler {
    // 资源有的参数，兜底方法也必须有
    public static Result<String> resourceHandleBlock(BlockException e) {
        return Result.success("请求资源被限流了, uuid = {}", IdUtil.fastSimpleUUID());
    }

    public static Result<String> urlHandleBlock(BlockException e) {
        return Result.success("请求url被限流了, uuid = {}", IdUtil.fastSimpleUUID());
    }

    public static Result<String> defaultHandleBlock(BlockException e) {
        return Result.success("请求被限流了, uuid = {}", IdUtil.fastSimpleUUID());
    }

    // 注意参数顺序，blockHandler：Long id, BlockException e，fallback：Long id, Throwable e，都是参数在前，异常类在后
    public static Result<String> paymentInfoHandleBlock(Long id, BlockException e) {
        String message = e.getMessage();
        return Result.success("请求被限流了,id = {},message = {}, uuid = {}", id, message, IdUtil.fastSimpleUUID());
    }

}
